'''
Created on Apr 28, 2011

@author: user
'''
primes_under_100 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
def isprime(n):
    if n <= 100:
        return n in primes_under_100
    if n % 2 == 0 or n % 3 == 0:
        return False

    for f in range(5, int(n ** .5), 6):
        if n % f == 0 or n % (f + 2) == 0:
            return False
    return True 

def primeFiboGreaterThan(x):
    a = 1
    b = 1
    c = a + b
    a = b 
    b = c 
    while c < x:
        c = a + b
        a = b
        b = c
    
    while isprime(c) == False:
        c = a + b
        a = b
        b = c
    print c


if __name__ == '__main__':
    primeFiboGreaterThan(217000)